//
//  ViewController.m
//  xxShare
//
//  Created by 柳麟喆 on 2018/3/5.
//  Copyright © 2018年 lzLiu. All rights reserved.
//

#import "ViewController.h"
#import "FeedViewController.h"
#import "MessageViewController.h"
#import "PostViewController.h"
#import "FindViewController.h"
#import "MeViewController.h"
#import "LLZTabBar.h"
#import "TZImagePickerController.h"
#import "PublishViewController.h"

@interface ViewController ()<TZImagePickerControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    LLZTabBar *llzTabBar = [[LLZTabBar alloc]init];
    [llzTabBar setCenterBtnClick:^(LLZTabBar *tabBar, UIButton *centerBtn) {
//        PostViewController *post = [[PostViewController alloc]init];
//        post.modalPresentationStyle = UIModalPresentationOverFullScreen;
//        [self presentViewController:post animated:YES completion:nil];
        TZImagePickerController *picker = [[TZImagePickerController alloc]initWithMaxImagesCount:9 delegate:self];
        picker.allowTakePicture = YES;
        [picker setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            
            PublishViewController *publish = [[PublishViewController alloc]init];
            publish.selectedAssets = [NSMutableArray arrayWithArray:assets];
            publish.selectedPhotos = [NSMutableArray arrayWithArray:photos];
            publish.isSelectOriginalPhoto = isSelectOriginalPhoto;
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:publish];
            [self presentViewController:nav animated:YES completion:nil];
        }];
        [self presentViewController:picker animated:YES completion:nil];
    }];
    //用KVO使用自定义的tabBar
    [self setValue:llzTabBar forKey:@"tabBar"];
    self.tabBar.tintColor = [UIColor redColor];
    FeedViewController *feed = [[FeedViewController alloc]init];
    MessageViewController *message = [[MessageViewController alloc]init];
    FindViewController *find = [[FindViewController alloc]init];
    MeViewController *me = [[MeViewController alloc]init];
    self.viewControllers = [self viewcontrollers:@[feed,message,find,me]
                                          titles:@[@"首页",@"消息",@"推荐",@"我的"]
                                      imageNames:@[@"主页-蓝色-32",@"消息-黑色-32.png",@"搜索-黑色-32.png",@"我的-黑色-32.png"]];
    self.selectedIndex = 2;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSArray <UIViewController *> *)viewcontrollers: (NSArray <UIViewController *> *)viewcontrollers
                            titles:(NSArray <NSString *> *)titles
                            imageNames:(NSArray <NSString *> *)images{
    ///设置tabbar的标题和图片
    for (int i = 0; i<viewcontrollers.count; i++){
        viewcontrollers[i].tabBarItem.title = titles[i];
        viewcontrollers[i].tabBarItem.image = [UIImage imageNamed:images[i]];
        viewcontrollers[i].view.backgroundColor = BACKGROUND_COLOR;
    }
    ///转化成navgationcontroller
    NSMutableArray <UINavigationController *> * vcs = [[NSMutableArray alloc]init];
    for (UIViewController *vc in viewcontrollers){
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
        [vcs addObject:nav];
    }
    return vcs;
}

@end
